home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1996 #15 / Monster Media Number 15 (Monster Media)(July 1996).ISO / bbs_util / bsrc_260.zip / SRC.ZIP / B_PROTO.C < prev    next >
C/C++ Source or Header  |  1996-03-23  |  7KB  |  175 lines

  1. /*--------------------------------------------------------------------------*/
  2. /*                                                                          */
  3. /*                                                                          */
  4. /*      ------------         Bit-Bucket Software, Co.                       */
  5. /*      \ 10001101 /         Writers and Distributors of                    */
  6. /*       \ 011110 /          Freely Available<tm> Software.                 */
  7. /*        \ 1011 /                                                          */
  8. /*         ------                                                           */
  9. /*                                                                          */
  10. /*              (C) Copyright 1987-96, Bit Bucket Software Co.              */
  11. /*                                                                          */
  12. /*               This module was written by Vince Perriello                 */
  13. /*                                                                          */
  14. /*              BinkleyTerm External Protocol Handler Module                */
  15. /*                                                                          */
  16. /*                                                                          */
  17. /*    For complete  details  of the licensing restrictions, please refer    */
  18. /*    to the License  agreement,  which  is published in its entirety in    */
  19. /*    the MAKEFILE and BT.C, and also contained in the file LICENSE.260.    */
  20. /*                                                                          */
  21. /*    USE  OF THIS FILE IS SUBJECT TO THE  RESTRICTIONS CONTAINED IN THE    */
  22. /*    BINKLEYTERM  LICENSING  AGREEMENT.  IF YOU DO NOT FIND THE TEXT OF    */
  23. /*    THIS  AGREEMENT IN ANY OF THE  AFOREMENTIONED FILES,  OR IF YOU DO    */
  24. /*    NOT HAVE THESE FILES,  YOU  SHOULD  IMMEDIATELY CONTACT BIT BUCKET    */
  25. /*    SOFTWARE CO.  AT ONE OF THE  ADDRESSES  LISTED BELOW.  IN NO EVENT    */
  26. /*    SHOULD YOU  PROCEED TO USE THIS FILE  WITHOUT HAVING  ACCEPTED THE    */
  27. /*    TERMS  OF  THE  BINKLEYTERM  LICENSING  AGREEMENT,  OR  SUCH OTHER    */
  28. /*    AGREEMENT AS YOU ARE ABLE TO REACH WITH BIT BUCKET SOFTWARE, CO.      */
  29. /*                                                                          */
  30. /*                                                                          */
  31. /* You can contact Bit Bucket Software Co. at any one of the following      */
  32. /* addresses:                                                               */
  33. /*                                                                          */
  34. /* Bit Bucket Software Co.        FidoNet  1:104/501, 1:343/491             */
  35. /* P.O. Box 460398                AlterNet 7:42/1491                        */
  36. /* Aurora, CO 80046               BBS-Net  86:2030/1                        */
  37. /*                                Internet f491.n343.z1.fidonet.org         */
  38. /*                                                                          */
  39. /* Please feel free to contact us at any time to share your comments about  */
  40. /* our software and/or licensing policies.                                  */
  41. /*                                                                          */
  42. /*--------------------------------------------------------------------------*/
  43.  
  44. /* Include this file before any other includes or defines! */
  45.  
  46. #include "includes.h"
  47.  
  48. #ifdef Snoop
  49. #include "snserver.h"
  50. extern HSNOOP hsnoop;
  51. #endif
  52.  
  53. void 
  54. do_extern (char *cmd, int prot, char *name)
  55. {
  56.     int j;
  57.     struct baud_str *i;
  58.     char rgchT[100];
  59.     char *c, *p, *m;
  60.     FILE *ctlfile;
  61.  
  62.     for (j = 0; j < 100; j++)                        /* Make sure it's all   */
  63.         rgchT[j] = '\0';                            /* zeroes...            */
  64.  
  65.     for (j = 0; j < 5; j++)
  66.     {
  67.         if (protos[j].first_char == (char) prot)
  68.             break;
  69.     }
  70.     j = protos[j].entry;
  71.     c = m = protocols[j];
  72.     p = NULL;
  73.     while (*m)                                        /* Until end of string  */
  74.     {
  75.         if ((*m == '\\') || (*m == ':'))            /* Look for last path   */
  76.             p = m;                                    /* Delimiter            */
  77.         m++;
  78.     }
  79.     m = &rgchT[0];
  80.  
  81.     /* It doesn't pay to be too smart here. Dots can appear in dir names */
  82.  
  83.     while (c != p)                                    /* Copy to last '\'     */
  84.         *m++ = *c++;
  85.     while (*c != '.')                                /* Then to the dot      */
  86.         *m++ = *c++;
  87.     (void) strcat (&rgchT[0], ".ctl");                /* Then add extension   */
  88.  
  89.    /*
  90.     * At this point we have the Control File name in (rgchT), Now let's open
  91.     * the file and put our good stuff in there.
  92.     */
  93.  
  94.     (void) unlink (rgchT);                            /* Delete old copies    */
  95.     if ((ctlfile = fopen (rgchT, append_ascii)) == NULL) /* Try to open it  */
  96.     {
  97.         status_line (MSG_TXT (M_NO_CTL_FILE), rgchT);
  98.         return;
  99.     }
  100.  
  101.     (void) fprintf (ctlfile, "Port %d\n", (port_ptr + 1));    /* Port n       */
  102.     if (lock_baud && (cur_baud.rate_value >= lock_baud))
  103.         i = &max_baud;
  104.     else
  105.         i = &pbtypes[baud];
  106.  
  107.     (void) fprintf (ctlfile, "Modem %lx %lx %x %x %x\n",    /* All modem params */
  108.         (unsigned long)hfComHandle, i->rate_value, handshake_mask, carrier_mask, i->rate_mask);
  109.  
  110.     (void) fprintf (ctlfile, "Baud %lu\n", i->rate_value);    /* Baud Rate    */
  111.     (void) fprintf (ctlfile, "%s %s\n", cmd, name);        /* Actual command   */
  112.     (void) fclose (ctlfile);
  113.  
  114.     /* The file is now written. Turn off everything. */
  115.  
  116.     if (!share)
  117.         MDM_DISABLE ();                                    /* Turn off FOSSIL  */
  118.  
  119. #ifdef Snoop
  120.     if (hsnoop != (HSNOOP) 0L)
  121.         snoop_close ();
  122. #endif                            /* Snoop */
  123.  
  124.     /* Close status log if need be */
  125.  
  126.     if (status_log != NULL)
  127.         (void) fclose (status_log);
  128.  
  129.     /* Do the same with the cost log */
  130.  
  131.     if (cost_log != NULL)
  132.         (void) fclose (cost_log);
  133.  
  134. #if defined(OS_2) | defined(_WIN32)
  135.     ComPause (hcModem);
  136. #endif
  137.  
  138.     /* We're all set. Build the command and execute it. */
  139.  
  140.     c = protocols[j];
  141.     (void) sprintf (e_input, "%s %s -p%lu -b%u %s", c, c, (unsigned long)hfComHandle, i->rate_value, rgchT);
  142.  
  143.     b_spawn (e_input);                                    /* Execute command  */
  144.  
  145.     /* Back from external protocol. Turn it all back on. */
  146.  
  147.     if (Cominit (port_ptr, buftmo) != 0x1954)            /* FOSSIL back on   */
  148.     {
  149.         (void) printf ("\n%s\n", MSG_TXT (M_FOSSIL_GONE));
  150.         exit (1);
  151.     }
  152.  
  153.     if (status_log != NULL)                                /* Reopen status log*/
  154.     {
  155.         if ((status_log = share_fopen (log_name, append_ascii, DENY_WRITE)) == NULL)
  156.         {
  157.             (void) printf ("\n%s\n", MSG_TXT (M_NO_LOGFILE));
  158.             status_log = NULL;
  159.         }
  160.     }
  161.  
  162.     if (cost_log != NULL)                                /* Reopen cost log*/
  163.     {
  164.         if ((cost_log = share_fopen (cost_log_name, append_ascii, DENY_WRITE)) == NULL)
  165.         {
  166.             (void) printf ("\n%s\n", MSG_TXT (M_NO_COSTFILE));
  167.             cost_log = NULL;
  168.         }
  169.     }
  170.  
  171.     program_baud ();
  172.     XON_ENABLE ();                                        /* and reenable XON */
  173. }
  174.  
  175.